
clear all 

//define folder global here

gl Inputs "$folder\1_Inputs"
gl Intermediate "$folder\2_Intermediate"
gl Outputs "$folder\3_Outputs"

********************************************************************************

clear
set seed 5172022

*Sample size comes from Table 1
local obs=193000+108000
local evictrate=193/(108+193)
set obs `obs'

gen evicted=runiform()>`evictrate'

gen move=runiform()<.039
replace move=0 if evicted==1

*$445 comes from the cook county specific estimate in Q1-4 in Table 6
*4821 and (5810) comes from mean and sd of the non-evicted group in cook county of earnings in Q1-4
gen earnings=4821+rnormal()*5810-445*evicted

eststo clear
eststo sim1: reg earnings evicted
local obs1: di %12.2gc e(N)
estadd local obs "`obs1'", replace	
sum  earnings if e(sample)
local ymean1: di %8.0f r(mean)
estadd local ymean "`ymean1'", replace	
local sd1: di %8.0f r(sd)
estadd local sd "`sd1'", replace

*Impute selection of the movers
local spec=2
foreach earn of numlist 100 200 500 1000  {

	*Same parameters as above but non-evicted movers are negatively selected
	replace earnings=earnings-`earn'*(move)*(1-evicted)
	
	*The conditional gap is preserved (because we are imputing for the movers)
	reg earnings evicted if move==0
	
	*The unconditional gap changes with the extent of selection for movers
	eststo sim`spec': reg earnings evicted 
	local obs1: di %12.2gc e(N)
	estadd local obs "`obs1'", replace	
	
	sum  earnings if e(sample)
	local ymean1: di %8.0f r(mean)
	estadd local ymean "`ymean1'", replace	
	local sd1: di %8.0f r(sd)
	estadd local sd "`sd1'", replace
	
	local spec=`spec'+1
}

*Output
label var evicted "Quarterly earnings"
esttab sim1 sim2 sim3 sim4 sim5 using "${Outputs}/Supplementary data_Table_I2.tex", ///
	replace compress nomtitles wrap booktabs nonotes label  se(2) b(2) ///
	eqlabels(none) keep(evicted)  star(* 0.10 ** 0.05 *** 0.01) ///
	stats( obs r2 ymean sd, fmt(0 3 0 0)  ///
	 labels(`"Number of observations"' `"\(R^{2}\)"' `"Mean of dependent variable"' `"S.d. of dependent variable"') ) ///
		 mgroups(  "Baseline" "\\$100" "\\$200" "\\$500" "\\$1000", pattern( 1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(})   ///
		span erepeat(\cmidrule(lr){@span})) 
	